package com.norns.torque.bluetooth

import android.bluetooth.BluetoothAdapter
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent

class BluetoothBroadcastReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent) {
        val action: String? = intent.getAction()
        if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
            val state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)
            when (state) {
                BluetoothAdapter.STATE_OFF -> { // 蓝牙已关闭
                    ChatServer.bluetoothOff()
                }

                BluetoothAdapter.STATE_TURNING_ON -> {
                    // 蓝牙正在开启
                }

                BluetoothAdapter.STATE_ON -> { // 蓝牙已开启
                    ChatServer.bluetoothOpen()
                }

                BluetoothAdapter.STATE_TURNING_OFF -> {
                    // 蓝牙正在关闭
                }
            }
        }
    }
}
